package com.hhq.sso.system.controller;

import java.util.Map;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.hhq.sso.common.api.CommonResult;
import com.hhq.sso.common.page.Condition;
import com.hhq.sso.common.page.Query;
import com.hhq.sso.system.entity.Param;
import com.hhq.sso.system.service.IParamService;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.constant.RoleConstant;
import org.springblade.core.tool.utils.Func;
import org.springframework.web.bind.annotation.*;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.AllArgsConstructor;

/**
 * 控制器
 *
 * @author Chill
 */
@RestController
@AllArgsConstructor
@RequestMapping("/param")
@Tag(name = "参数管理", description = "接口")
public class ParamController {

    private IParamService paramService;

    /**
     * 详情
     */
    @GetMapping("/detail")
    @Operation(summary = "详情", description = "传入param")
    public CommonResult<Param> detail(Param param) {
        Param detail = paramService.getOne(Condition.getQueryWrapper(param));
        return CommonResult.data(detail);
    }

    /**
     * 分页
     */
    @GetMapping("/list")
    @Parameters({
        @Parameter(name = "paramName", description = "参数名称", in = ParameterIn.QUERY, schema = @Schema(type = "string")),
        @Parameter(name = "paramKey", description = "参数键名", in = ParameterIn.QUERY, schema = @Schema(type = "string")),
        @Parameter(name = "paramValue", description = "参数键值", in = ParameterIn.QUERY,
            schema = @Schema(type = "string"))})
    @Operation(summary = "分页", description = "传入param")
    public CommonResult<IPage<Param>> list(@Parameter(hidden = true) @RequestParam Map<String, Object> param,
        Query query) {
        IPage<Param> pages = paramService.page(Condition.getPage(query), Condition.getQueryWrapper(param, Param.class));
        return CommonResult.data(pages);
    }

    /**
     * 新增或修改
     */
    @PostMapping("/submit")
    @Operation(summary = "新增或修改", description = "传入param")
    public CommonResult<Boolean> submit(@Valid @RequestBody Param param) {
        return CommonResult.status(paramService.saveOrUpdate(param));
    }

    /**
     * 删除
     */
    @PostMapping("/remove")
    @Operation(summary = "逻辑删除", description = "传入ids")
    public CommonResult<Boolean>  remove(@Parameter(description = "主键集合", required = true) @RequestParam String ids) {
        return CommonResult.status(paramService.deleteLogic(Func.toLongList(ids)));
    }

}
